package com.example.a14110100420.yuejian.WAdapter.club;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WActivity.club.ClubDetailActivity;
import com.example.a14110100420.yuejian.Wbean.club.Clublist;
import com.example.a14110100420.yuejian.Wviewholder.club.ClublistViewholder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by wanger on 2017/11/13.
 */

public class ReqiClublistAdapter extends RecyclerView.Adapter {
    private View view;
    private Context context;
    private List list;
    private LayoutInflater inflater;
    public ReqiClublistAdapter(Context context,List list){
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view = inflater.from(parent.getContext()).inflate(R.layout.clublist_adapter,parent,false);
        ClublistViewholder clublistViewholder = new ClublistViewholder(view);

        return clublistViewholder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ClublistViewholder viewholder = (ClublistViewholder) holder;
        Clublist clublist = (Clublist) list.get(position);
        if(null == clublist){
            return;
        }
        final String clubname = clublist.getClub_name();
        final String clubpic = clublist.getThumb();
        final String clubid = clublist.getId();
        viewholder.clubname.setText(clubname);
        Picasso.with(context)
                .load("http://172.24.10.175/workout/Uploads/"+clubpic)
                .into(viewholder.clubpic);

        viewholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"晒图详情",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, ClubDetailActivity.class);
                intent.putExtra("clubid",clubid);
                context.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
